<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品生产工序设计单变更</title>
</head>
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">


<link rel="stylesheet" href="../../css/bootstrap-table.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>



<script src="../../js/bootstrap-table.min.js"></script>

<script src="../../js/bootstrap-table-zh-CN.min.js"></script>
<body>

<!--变更-->
<div class="modal fade" id="changproductmoble">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h6 class="modal-title">您正在做的业务是：生产管理--产品生产工序设计--产品生产工序设计单变更
                </h6>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body" style="background-color: darkgray;">
                <div style="display: flex;justify-content: flex-end">
                    <button type="button" class="btn btn-primary" onclick="addnewgxu()" data-toggle="modal" data-target="#addgxubiao" >添加新工序</button>
                    <button type="button" class="btn btn-primary" onclick="delenewgxu()" >删除新工序</button>
                    <button type="button" class="btn btn-info" onclick="returntjiao()" data-dismiss="modal">重新提交</button>
                    <button type="button" class="btn btn-secondary"style="margin-left: 5px;" data-dismiss="modal">取消</button>
                </div>

                <div style="border: 1px solid black;margin-top: 10px; background-color: white;display: flex;flex-direction: column">
                    <h5 style="text-align: center;margin-top: 20px">生产工序设计单</h5>
                    <div style="display: flex;">
                        <div  style="margin-left: 10%;width: 40%;" >设计单编号：<span id="change_designId"></span></div>
                        <div style="width: 40%;display: flex"><div style="width: 23%">设计人：</div><input id="change_designer"  style="outline: none;border: none;border-bottom: 1px solid black;width: 80%"></div>
                    </div>
                    <div  style="display: flex;margin-top: 5px;">
                        <div  style="margin-left: 10%;width: 30%;" >产品名称：<span id="change_productName"></span></div>
                        <div  style="margin-left: 10%;width: 40%;" >产品编号：<span id="chang_productId"></span></div>
                    </div>
                    <div style="display: flex;">
                        <table class="table-sm  table-hover table-bordered" id="changecahngtab" style="margin-left: 10%;margin-top: 5px;text-align: center" border="1" cellpadding="0" cellspacing="0" width="80%;">
                            <tr class="table-primary" style="color: white">
                                <td>工序序号</td>
                                <td>工序名称</td>
                                <td>工序编号</td>
                                <td>描述</td>
                                <td>工时数</td>
                                <td>工时单位</td>
                                <td>工时成本</td>
                                <td colspan="2">工时成本小计（元）</td>
                            </tr>
                        </table>
                    </div>
                    <div>
                        <div  style="margin-left: 10%;width: 30%;margin-top: 5px;" >工时总成本：<span id="sheng_costPriceSum"></span></div>
                    </div>
                    <div  style="display: flex;">
                        <div style="margin-left: 10%;margin-top: 5px;">
                            变更人 ：</div><input id="change_changer"  style="outline: none;border: none;border-bottom: 1px solid black;width: 30%;">
                        <div style="margin-left: 45px;margin-top: 20px;">变更时间：<span id="change_changeTime"></span></div>
                    </div>
                    <div style="display: flex;">
                        <div style="margin-left:10%;margin-top: 5px;display: flex;width: 100%;margin-bottom: 30px;">
                            设计要求：
                            <textarea id="change_procedureDescribe" rows="3" style="width: 77%;margin-top: 20px;"></textarea>
                            <input type="hidden" id="change_designModuleTag" value="1">
                            <input type="hidden" id="chang_id">
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<!--添加新工序-->
<div class="modal fade" id="addgxubiao">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h6 class="modal-title">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</h6>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body" style="background-color: white;height: 400px;">
                <div>
                    <button type="button" class="btn btn-secondary"style="margin-left: 700px;" data-dismiss="modal">返回</button>
                </div>

                <div style="display: flex;justify-content: center;margin-top: 16px;">
                    <h5 style="color: black">添加工序</h5>
                </div>
                <table class="table  table-hover table-bordered" border="1" cellspacing="0" cellpadding="0"style="width: 720px;margin-left: 20px; text-align: center;margin-top: 20px;" >
                    <tr class="table-primary">
                        <td>工序编号</td>
                        <td>工序名称</td>
                        <td>工序描述</td>
                        <td>工序添加</td>
                    </tr>
                    <tbody>
                    <tr>
                        <td>01</td>
                        <td>组装</td>
                        <td>&nbsp;</td>
                        <td><a href="#" id="tjiazz">添加</a></td>
                    </tr>
                    <tr>
                        <td>02</td>
                        <td>测试</td>
                        <td>&nbsp;</td>
                        <td><a href="#" id="tjiacs">添加</a></td>
                    </tr>
                    <tr>
                        <td>03</td>
                        <td>包装</td>
                        <td>&nbsp;</td>
                        <td><a href="#" id="tjbz">添加</a></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>



<div>
    <div class="form-inline">
        <label for="change_product_name" style="margin-left: 200px;">请输入产品名称：</label>
        <input id="change_product_name" class="form-control">
        <button  id="change_ss" class="btn btn-primary" style="margin-left: 20px;">点击搜索</button>
    </div>
</div>
<div>
    <table id="change_tabb">

    </table>
</div>

<script>
    //查询审核通过的生产工序
    $(function () {
        $("#change_tabb").bootstrapTable({
            method: "post",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            url: "/lc/querychangeproductionprocesses",
            striped: true,
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 3,
            pageList: [3, 5, 8, 10],
            queryParams: function (parms) {
                return {
                    pageNum: (parms.offset / parms.limit) + 1,
                    pageSize: parms.limit,
                    productName:$("#serach_product_name").val()
                }
            },
            columns: [
                {title: "设计单编号", field: "designId", align: "center"},
                {title: "产品编号", field: "productId", align: "center"},
                {title: "产品名称", field: "productName", align: "center"},
                {title: "设计人", field: "designer", align: "center"},
                {title: "登记时间", field: "registerTime", align: "center"},
                {title: "工时总成本", field: "costPriceSum", align: "center"},
                {title: "变更", field: "biangeng", align: "center",
                    formatter: function (value, row, index) {
                        //方式1
                        /*var btn1="<button  class='btn btn-primary btn-sm' data-toggle='modal' onclick='editEmp("+JSON.stringify(row)+")' data-target='#myModal'>修改</button>";*/
                        //方式2
                        var btn1 = "<button  class=\"btn btn-primary btn-sm\" data-toggle=\"modal\" onclick='changeproduct("+JSON.stringify(row)+")' data-target=\"#changproductmoble\">变更</button>";
                        return btn1;
                    }},
            ],
        })
        $("#change_ss").click(function () {
            $("#change_tabb").bootstrapTable("refresh")
        })


   $("#tjiazz").click(function () {
           var a=0
       $(".sheng_tr").each(function () {
           if($(this).find(" td:eq(1)").text()=='组装'){
             alert("不可重新添加相同工序")
               a=1
           }
       })
       if(a==0){
           $("#changecahngtab").append("<tr class='sheng_tr'>" +
               "<td><input type='checkbox' class='chang_sc'></td>" +
               "<td>组装</td>" +
               "<td>01</td>" +
               "<td></td>" +
               "<td><input type='text'   value='' style='border: none;outline: none;width: 40px;'></td>" +
               "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
               "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
               "<td></td>" +
               "</tr>")
       }
   })

        $("#tjiacs").click(function () {
            var a=0
            $(".sheng_tr").each(function () {
                if($(this).find(" td:eq(1)").text()=='测试'){
                    alert("不可重新添加相同工序")
                    a=1
                }
            })
            if(a==0){
                $("#changecahngtab").append("<tr class='sheng_tr'>" +
                    "<td><input type='checkbox' class='chang_sc'></td>" +
                    "<td>测试</td>" +
                    "<td>02</td>" +
                    "<td></td>" +
                    "<td><input type='text'   value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td></td>" +
                    "</tr>")
            }
        })

        $("#tjbz").click(function () {
            var a=0
            $(".sheng_tr").each(function () {
                if($(this).find(" td:eq(1)").text()=='包装'){
                    alert("不可重新添加相同工序")
                    a=1
                }
            })
            if(a==0){
                $("#changecahngtab").append("<tr class='sheng_tr'>" +
                    "<td><input type='checkbox' class='chang_sc'></td>" +
                    "<td>包装</td>" +
                    "<td>03</td>" +
                    "<td></td>" +
                    "<td><input type='text'   value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td><input type='text' value='' style='border: none;outline: none;width: 40px;'></td>" +
                    "<td></td>" +
                    "</tr>")
            }
        })

    })

    function  changeproduct(qq) {
        $("#chang_id").val(qq.id)
        $("#change_designId").text(qq.designId);
        $("#change_designer").val(qq.designer);
        $("#change_productName").text(qq.productName);
        $("#chang_productId").text(qq.productId);
        $("#sheng_costPriceSum").text(qq.costPriceSum);
        $("#change_designModuleTag").val(qq.designModuleTag)
        //变更人:当前登录用户
        $.ajax({
            type:"post",
            url:"/SysUser/queryUser",
            success:function (user) {
                $("#change_changer").val(user.loginId)
            }
        })
        //变更时间：当前时间
        var myDate = new Date;
        $("#change_changeTime").text(myDate.toLocaleString());
        $("#change_procedureDescribe").val(qq.procedureDescribe);
        $(".sheng_tr").remove();
        $.ajax({
            type:"POST",
            data:"id="+qq.id,
            url:"/lc/queryByidcheckmingxi",
            success:function (iddata) {
                $.each(iddata,function (index,d) {
                    $("#changecahngtab").append("<tr class='sheng_tr'>" +
                        "<td>"+d.detailsNumber+"</td>" +
                        "<td>"+d.procedureName+"</td>" +
                        "<td>"+d.procedureId+"</td>" +
                        "<td><input type='hidden' value='"+d.id+"'></td>" +
                        "<td><input type='number'   value='"+d.labourHourAmount+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td><input type='text' value='"+d.amountUnit+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td><input type='number' value='"+d.costPrice+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td>"+d.subtotal+"</td>" +
                        "<td><a href='#'onclick='deletetrhtitr($(this).parent().parent())'>删除</a> </td>" +
                        "</tr>")
                })
            }
        })
    }
    //删除
    function  deletetrhtitr(z) {
    z.remove()
    }

    // 删除新工序
    function  delenewgxu() {
        $(".chang_sc").each(function () {
            if($(this).prop("checked")==true){
                $(this).parent().parent().remove();
            }
        })
    }
    
    //重新提交
    function returntjiao() {
        // 产品工序设计
        var zcb = 0;
        //产品工序设计明细
        gxmxobj = {},
            gxumxnumobj = [];
        $(".sheng_tr").each(function () {
            zcb += parseInt($(this).find(" td:eq(4)>input").val() * $(this).find(" td:eq(6)>input").val())
            gxmxobj = {
                id:$(this).find(" td:eq(3)>input").val(),
                procedureId: $(this).find(" td:eq(2)").text(),
                procedureName: $(this).find(" td:eq(1)").text(),
                labourHourAmount: parseInt($(this).find(" td:eq(4)>input").val()),
                amountUnit: $(this).find(" td:eq(5)>input").val(),
                costPrice: parseInt($(this).find(" td:eq(6)>input").val()),
                subtotal: parseInt($(this).find(" td:eq(4)>input").val() * $(this).find(" td:eq(6)>input").val())
            }
            gxumxnumobj.push(gxmxobj)
        })
        updategx = {
            id: $("#chang_id").val(),
            designId: $("#change_designId").text(),
            productId: $("#chang_productId").text(),
            designer: $("#change_designer").val(),
            changer: $("#change_changer").val(),
            costPriceSum: parseInt(zcb),
            changeTime: $("#change_changeTime").text(),
            procedureDescribe: $("#change_procedureDescribe").val(),
            register: $("#change_changer").val(),
            registerTime: $("#change_changeTime").text()
        }
        //如果工序物料未设计
        if ($(".sheng_tr").length < 1) {
            alert("工序不能为空，请添加新工序")
        } else {
            if ($("#change_designModuleTag").val() == 'G002-0') {
                $.ajax({
                    type: "POST",
                    url: "/lc/changenosheji",
                    contentType: 'application/json',
                    data: JSON.stringify({
                        mdesignProcedure: updategx,
                        mdesignProcedureDetailslist: gxumxnumobj
                    }),
                    success: function (xx) {
                        $("#change_tabb").bootstrapTable("refresh")
                    }
                })
            } else {
                $.ajax({
                    type: "POST",
                    url: "/lc/changeoksheji",
                    contentType: 'application/json',
                    data: JSON.stringify({
                        mdesignProcedure: updategx,
                        mdesignProcedureDetailslist: gxumxnumobj
                    }),
                    success: function (xx) {
                        $("#change_tabb").bootstrapTable("refresh")
                    }
                })
            }
        }
    }
</script>
</body>
</html>